package com.netty.encodedecode.protol;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

import java.nio.charset.Charset;

/**
 * @auther: cc.ly
 * @date: 2019/1/12/012
 */

public class ClientHandler extends SimpleChannelInboundHandler<PersonProtol> {

    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
        System.out.println("connect sucess");
    }

    @Override
    public void channelRead0(ChannelHandlerContext ctx, PersonProtol msg) throws Exception {
        int length = msg.getLength();

        String src = new String(msg.getContent(), Charset.forName("utf-8"));
        System.out.println(length + "=收到." + src);

        ctx.channel().writeAndFlush(msg);
    }
}
